﻿@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>修改工资</title>
    <link rel="stylesheet" href="~/layui-v2.5.5/layui/css/layui.css" media="all">
</head>
<body>
    <form id="wagedetail"class="layui-form layui-form-pane" lay-filter="ShowWageDetail"action=""style="margin:20px">
           
            <div class="layui-form-item  ">
                <label class="layui-form-label">教师ID</label>
                <div class="layui-input-block">
                    <input type="text" name="teacherid" readonly class="layui-input" style="color:gray" >
                </div>
            </div>
            <div class="layui-form-item  ">
                <label class="layui-form-label">工资日期</label>
                <div class="layui-input-block">
                    <input type="text" name="wagetime" readonly class="layui-input" style="color:gray">
                </div>
            </div>
            <div class="layui-form-item  ">
                <label class="layui-form-label">基本工资</label>
                <div class="layui-input-block">
                    <input type="text" name="basicwage" class="layui-input">
                    <span style="display:none" id="bw">输入有误，请重新输入</span>
                </div>
            </div>
            <div class="layui-form-item  ">
                <label class="layui-form-label">加班工资</label>
                <div class="layui-input-block">
                    <input type="text" name="overtimewage" class="layui-input">
                    <span style="display:none" id="ow">输入有误，请重新输入</span>
                </div>
            </div>
            <div class="layui-form-item  ">
                <label class="layui-form-label">福利工资</label>
                <div class="layui-input-block">
                    <input type="text" name="welfare" class="layui-input">
                    <span style="display:none" id="wf">输入有误，请重新输入</span>
                </div>
            </div>
            <div class="layui-form-item  ">
                <label class="layui-form-label">全勤工资</label>
                <div class="layui-input-block">
                    <input type="text" name="bonus" class="layui-input">
                    <span style="display:none" id="bn">输入有误，请重新输入</span>
                </div>
            </div>
            <div class="layui-form-item  ">
                <label class="layui-form-label">总工资</label>
                <div class="layui-input-block">
                    <input type="text" name="totalwage" readonly class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                @*<div class="layui-input-block">*@
                    <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="buttonsubmit" style="text-align :center" id="ShowWageDetail">立即提交</button>
                @*</div>*@

            </div>
    </form>
   
        @*</fieldset>*@

        <script src="~/layui-v2.5.5/layui/layui.js"></script>
        <script src="~/js/jquery.js"></script>
        <script>

        layui.use(['form','layer'], function () {
            var form = layui.form;
            var layer = layui.layer;
            var $ = jQuery;
            var WageData;
            var iid = new Number();; //记录ID
            //各种基于事件的操作，下面会有进一步介绍
            $.ajax({
                url: '/Api/QueryTeacherWage',
                data: {
                    teacherid: '@ViewData["teacherid"]'
                    ,time: '@ViewData["time"]'
                    },
                type: "GET",
                dataType: "JSON",
                success: function (data) {
                    WageData = data;
                    iid = WageData.wageList[0].id;
                    console.log(typeof iid);
                    form.val('ShowWageDetail', {
                        "teacherid": WageData.wageList[0].teacherid
                        , "wagetime": WageData.wageList[0].wagetime.substring(0,7)
                        , "basicwage": WageData.wageList[0].basicwage
                        , "overtimewage": WageData.wageList[0].overtimewage
                        , "welfare": WageData.wageList[0].welfare
                        , "bonus": WageData.wageList[0].bonus
                        , "totalwage": WageData.wageList[0].totalwage
                    });
                }
            })
            //监听提交
            form.on('submit(buttonsubmit)', function (obj) {         
                var basicwage0 = $(" input[ name='basicwage' ] ").val()
                var overtimewage0 = $(" input[ name='overtimewage' ] ").val()
                var welfare0 = $(" input[ name='welfare' ] ").val()
                var bonus0 = $(" input[ name='bonus' ] ").val()
             
                if (!(/(^[0-9]\d*$)/.test(basicwage0))) {
                    $("#bw").css('display', 'block');
                    $("#bw").css('color','green');
                     return false;
　　　　        }if (!(/(^[0-9]\d*$)/.test(overtimewage0 ))) {
                     $("#ow").css('display', 'block');  
                     $("#ow").css('color','green');                  
                     return false;
　　　　        }if (!(/(^[0-9]\d*$)/.test(welfare0))) {
                     $("#wf").css('display', 'block');
                     $("#wf").css('color','green');
                    return false;
                } if (!(/(^[0-9]\d*$)/.test(bonus0))) {
                    $("#bn").css('display', 'block');
                    $("#bn").css('color','green');
                    return false;
                } else {
                    $("#bw").css('display', 'none');
                    $("#ow").css('display', 'none');
                    $("#wf").css('display', 'none');
                    $("#bn").css('display', 'none');
                    var tabledata = obj.field;
                    $.ajax({
                        url: '/Api/UpdateWage',
                        data: {
                            id : iid,
                            basicwage :tabledata.basicwage,
                            overtimewage :tabledata.overtimewage,
                            welfare :tabledata.welfare,
                            bonus :tabledata.bonus
                            },
                        type: "GET",
                        dataType: "JSON",
                        success: function (data) {
                            WageData = data;
                            layer.open({
                              content: WageData.msg
                            });
                            //form.val('ShowWageDetail', {
                            //    "teacherid": WageData.wage.teacherid
                            //    , "wagetime": WageData.wage.wagetime.substring(0,7)
                            //    , "basicwage": WageData.wage.basicwage
                            //    , "overtimewage": WageData.wage.overtimewage
                            //    , "welfare": WageData.wage.welfare
                            //    , "bonus": WageData.wage.bonus
                            //    , "totalwage": WageData.wage.totalwage
                            //});
                            //刷新本页
                            setTimeout(function(){
                                window.parent.location.reload();//修改成功后刷新父界面
                            }, 1500);
                        }
                    })
                  }

              return false;
            });
        });
        </script>
</body>
</html>